#include <gtk/gtk.h>
#include "callback.h"

int main (int argc,
          char *argv[])
{
    gtk_init (&argc, &argv);
    builder=gtk_builder_new();
    guint id,id2;

    gtk_builder_add_from_file(builder,"pudingmu.glade",NULL);
    gtk_builder_connect_signals(builder,NULL); //mengambil signal callback dari model

    window=GTK_WIDGET(gtk_builder_get_object(builder,"window1")); //main GUI
    cover=GTK_WIDGET(gtk_builder_get_object(builder,"imgCover"));
    //togglebutton
    togJudul=GTK_WIDGET(gtk_builder_get_object(builder,"togglebutton1"));
    togDesk=GTK_WIDGET(gtk_builder_get_object(builder,"togglebutton2"));
    togPen=GTK_WIDGET(gtk_builder_get_object(builder,"togglebutton3"));
    togTeks=GTK_WIDGET(gtk_builder_get_object(builder,"togglebutton4"));
    //navigasi
    awal=GTK_WIDGET(gtk_builder_get_object(builder,"awal"));
    prev=GTK_WIDGET(gtk_builder_get_object(builder,"prev"));
    next=GTK_WIDGET(gtk_builder_get_object(builder,"next"));
    end=GTK_WIDGET(gtk_builder_get_object(builder,"end"));
    //search entry
    searchBtn=GTK_WIDGET(gtk_builder_get_object(builder,"cari"));
    searchEntry=GTK_WIDGET(gtk_builder_get_object(builder,"entry1"));



    //statusTable
    statusTable=GTK_WIDGET(gtk_builder_get_object(builder,"statusbar2"));
    id2=gtk_statusbar_get_context_id(GTK_STATUSBAR(statusTable),"Table pudingmu");
    statustable_context_id=id2;
    //gtk_statusbar_push(GTK_STATUSBAR(statusTable),statustable_context_id,"list tabel utama");
    kolView=GTK_WIDGET(gtk_builder_get_object(builder,"treeview1"));
    //kol_scrolled_win=GTK_WIDGET(gtk_builder_get_object(builder,"scrolledwindow6"));
    //gtk_container_add (GTK_CONTAINER(kol_scrolled_win), kolView);
    //gtk_widget_show_all(kol_scrolled_win);
    setup_kol_view(kolView);
    setup_kol_model(kolView);

    //select row
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(kolView));
    gtk_tree_selection_set_select_function(selection, view_selection_func, NULL, NULL);

    //statusbarMain
    statusMain=GTK_WIDGET(gtk_builder_get_object(builder,"statusbarMain"));
    id=gtk_statusbar_get_context_id(GTK_STATUSBAR(statusMain),"PudingMu Pustaka Dijital Muhammadiyah");
    statusbar_context_id=id;
    gtk_statusbar_push(GTK_STATUSBAR(statusMain),statusbar_context_id,"Percobaan PudingMu");
    //statusTable


    //add koleksi
    dialog2=GTK_DIALOG(gtk_builder_get_object(builder,"addKoleksi"));//dialog untuk menambah koleksi
    entryID=GTK_WIDGET(gtk_builder_get_object(builder,"entryID"));
    entryJdl=GTK_WIDGET(gtk_builder_get_object(builder,"entryJdl"));
    cbJenis=GTK_WIDGET(gtk_builder_get_object(builder,"comboboxJns"));
    cbKategori=GTK_WIDGET(gtk_builder_get_object(builder,"comboboxKat"));
    cbPenerbit=GTK_WIDGET(gtk_builder_get_object(builder,"comboboxPen"));
    tahun=GTK_WIDGET(gtk_builder_get_object(builder,"entryTahun"));//mendeklarasikan combobox tahun
    fileChooser=GTK_WIDGET(gtk_builder_get_object(builder,"filechooserbutton1"));
    desText=GTK_WIDGET(gtk_builder_get_object(builder,"textview1"));
    btnOkKol=GTK_WIDGET(gtk_builder_get_object(builder,"btnOkKol"));
    btnBatalKol=GTK_WIDGET(gtk_builder_get_object(builder,"btnBatalKol"));
    setup_combo_jenis(cbJenis);
    setup_combo_kategori(cbKategori);
    setup_combo_penerbit(cbPenerbit);
    //setup_combo_tahun(tahun);
    //gtk_combo_box_append_text(GTK_COMBO_BOX(tahun), "1992");

    //about
    aboutdialog=GTK_DIALOG(gtk_builder_get_object(builder,"aboutdialog1")); //dialog tentang

    //dialog addjenis
    jenis=GTK_DIALOG(gtk_builder_get_object(builder,"addJenis"));
    entryIDjns=GTK_WIDGET(gtk_builder_get_object(builder,"entryIDjns"));
    entryNamaJns=GTK_WIDGET(gtk_builder_get_object(builder,"entryNamaJns"));
    btnSimpanJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnSimpanJns"));
    btnBatalJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnBatalJns"));
    btnTambahJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnTambahJns"));
    btnEditJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnEditJns"));
    btnHapusJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnHapusJns"));
    btnCloseJns=GTK_WIDGET(gtk_builder_get_object(builder,"btnCloseJns"));

    jenisView=setup_jenis_view();
    scrolled_win=GTK_WIDGET(gtk_builder_get_object(builder,"scrolledwindow3"));
    gtk_container_add (GTK_CONTAINER(scrolled_win), jenisView);
    gtk_widget_show_all(scrolled_win);
    //selection=gtk_tree_view_get_selection(GTK_TREE_VIEW(jenisView));

    //add penerbit
    penerbit=GTK_DIALOG(gtk_builder_get_object(builder,"addPenerbit"));
    entryIDPen=GTK_WIDGET(gtk_builder_get_object(builder,"entryIDPen"));
    entryNamaPen=GTK_WIDGET(gtk_builder_get_object(builder,"entryNamaPen"));
    penTextview=GTK_WIDGET(gtk_builder_get_object(builder,"textview4"));
    btnSimpanPen=GTK_WIDGET(gtk_builder_get_object(builder,"btnSimpanPen"));
    btnBatalPen=GTK_WIDGET(gtk_builder_get_object(builder,"btnBatalPen"));
    btnTambahPen=GTK_WIDGET(gtk_builder_get_object(builder,"btnTambahPen"));
    btnEditPen=GTK_WIDGET(gtk_builder_get_object(builder,"btnEditPen"));
    btnHapusPen=GTK_WIDGET(gtk_builder_get_object(builder,"btnHapusPen"));
    btnClosePen=GTK_WIDGET(gtk_builder_get_object(builder,"btnClosePen"));

    penView=setup_pen_view();
    pen_scrolled_win=GTK_WIDGET(gtk_builder_get_object(builder,"scrolledwindow5"));
    gtk_container_add(GTK_CONTAINER(pen_scrolled_win),penView);
    gtk_widget_show_all(pen_scrolled_win);

    //add kategori
    kategori=GTK_DIALOG(gtk_builder_get_object(builder,"addKategori"));
    entryIDKat=GTK_WIDGET(gtk_builder_get_object(builder,"entryIDKat"));
    entryNamaKat=GTK_WIDGET(gtk_builder_get_object(builder,"entryNamaKat"));
    katTextview=GTK_WIDGET(gtk_builder_get_object(builder,"textview3"));
    btnSimpanKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnSimpanKat"));
    btnBatalKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnBatalKat"));
    btnTambahKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnTambahKat"));
    btnEditKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnEditKat"));
    btnHapusKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnHapusKat"));
    btnCloseKat=GTK_WIDGET(gtk_builder_get_object(builder,"btnCloseKat"));

    katView=setup_kat_view();
    kat_scrolled_win=GTK_WIDGET(gtk_builder_get_object(builder,"scrolledwindow4"));
    gtk_container_add(GTK_CONTAINER(kat_scrolled_win),katView);
    gtk_widget_show_all(kat_scrolled_win);

    //info
    info=GTK_WIDGET(gtk_builder_get_object(builder,"info"));


    //looping utama
    g_object_unref(G_OBJECT(builder));//mengosongkan memory object

    gtk_widget_show(window);//menampilkan window utama
    //gtk_dialog_run(dialog2);
    gtk_main();
    return 0;
}
